<template>
	<view class="content font_family">
		<view class="set_dynamic">
			<view class="title">
				<u-input placeholder="填写标题会有更多赞哦~" border="none" v-model="fb_data.title"></u-input>
			</view>
			<view class="dynamic_content">
				<u-input type="textarea" v-model="fb_data.content" border='none' height='150'
					placeholder="快来分享你的真实体验吧~可以带上明确的推荐 理由，更容易被推荐哦！"></u-input>
			</view>
			<u-upload width="200" height="200" ref="uUpload" @on-uploaded="onUploaded" @on-remove="onRemove"
				:action="uploadurl" :header="header" :form-data="formdata"></u-upload>
		</view>
		<!-- 发布按钮 -->
		<view class="btn_box f_z">
			<view class="btn f_zj" @click="submit">
				发布
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		computed: {},
		data() {
			return {
				images: '',
				content: '',
				show: false,
				fb_data: {
					title: '',
					content: '',
				},
			}
		},
		onLoad(e) {
			if (e.id) {
				this.get_detail(e.id)
			}
		},
		computed: {
			header() {
				return {
					token: this.vuex_token || '',
					uid: this.vuex_user.id || 0
				};
			},
			formdata() {
				let multipart = (this.vuex_config.config && this.vuex_config.config.upload.multipart) || '';
				let isObj = this.$u.test.object(multipart);
				if (isObj) {
					return this.vuex_config.config.upload.multipart;
				}
				return {};
			},
			uploadurl() {
				if (!this.vuex_config.upload) {
					return '';
				}
				return this.vuex_config.upload.uploadurl;
			}
		},
		methods: {
			onUploaded(e, name) {
				console.log(e, name);
				this.images = e
					.map(item => {
						return item.response.data.url;
					})
					.join(',');
			},
			onRemove(index, lists, name) {
				this.images = lists
					.map(item => {
						return item.response.data.url;
					})
					.join(',');
			},

			// 获取编辑详情
			get_detail(id) {


			},

			submit() {
				if (!this.fb_data.title) {
					this.$u.toast('请填写标题');
					return
				}
				if (!this.fb_data.content) {
					this.$u.toast('请填写内容');
					return
				}
				if (!this.images) {
					this.$u.toast('请上传图片');
					return
				}
				uni.showLoading({
					title: '提交中',
					mask: true
				});
				this.$api.uerArticleAdd({
					title: this.fb_data.title,
					content: this.fb_data.content,
					images: this.images
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						uni.showToast({
							title: '保存成功',
							mask: true
						});
						// this.fb_data = {
						// 	title: '',
						// 	content: '',
						// }
						// this.images = ''
						this.$refs.uUpload.clear()
						setTimeout(e => {
							uni.navigateBack()
						}, 2000)
						console.log(res)
					} else {
						this.$u.toast('稍后重试');
					}

				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #ffffff;

		.header {
			padding-left: 30rpx;

			.icon {
				width: 18rpx;
				height: 36rpx;
			}

			.item_box {
				margin-left: 30rpx;

				.item_action {
					font-size: 32rpx;
				}

				.item {
					font-weight: 400;
					font-size: 32rpx;
					color: #3D3D3D;
					margin-right: 40rpx;
				}

				.item_action {
					font-weight: 600;
					font-size: 36rpx;
				}
			}
		}

		.set_dynamic {
			padding: 30rpx;

			// margin-top: 70rpx;
			.type {
				margin-top: 30rpx;
				padding-bottom: 20rpx;

				.img {
					margin-left: 50rpx;
					// vertical-align: bottom;
				}

				.text {
					color: #999999;
					width: 250rpx;
				}
			}

			.title {
				padding-bottom: 25rpx;
				border-bottom: 2rpx solid #EEEEEE;
			}

			.dynamic_content {
				margin-top: 25rpx;
			}
		}



		.btn_box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			padding-bottom: 40rpx;

			.btn {
				width: 520rpx;
				height: 88rpx;
				background: #629A44;
				border-radius: 96rpx 96rpx 96rpx 96rpx;
				font-size: 28rpx;
				color: #fff;
			}
		}
	}
</style>